<!--
 * @Date: 2021-08-06 15:21:58
 * @LastEditTime: 2021-08-17 11:19:52
-->
<template>
  <div class="app-container">
    <div class="filter-container mb10">
      <el-input v-model="queryParam.tablename" size="small" placeholder="表名" clearable class="filter-item form-search-input" @keyup.enter.native="handleSearch" />
      <el-select v-model="queryParam.engine" size="small" clearable placeholder="请选择引擎" class="filter-item" style="margin-right: 5px">
        <el-option value="MyISAM" label="MyISAM" />
        <el-option value="InnoDB" label="InnoDB" />
      </el-select>
      <el-button size="small" type="primary" class="filter-item search" icon="el-icon-search" @click="handleSearch">
        搜索
      </el-button>
      <el-button size="small" class="filter-item" icon="el-icon-refresh" @click="handleRefresh">
        重置
      </el-button>
    </div>
    <div v-loading="loading">
      <el-table :data="data" tooltip-effect="dark" style="width: 100%" border fit :max-height="screenHeigh">
        <el-table-column type="index" align="center" label="序号" width="55" />
        <el-table-column label="表名" prop="name" width="180" />
        <el-table-column prop="engine" label="引擎" />
        <el-table-column prop="collation" label="字符集" width="180" />
        <el-table-column prop="rows" label="数据行数" />
        <el-table-column prop="index_length" label="索引大小">
          <template slot-scope="table">
            <el-tag type="success">{{ table.row.index_length }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="comment" label="注释" />
        <el-table-column prop="update_time" label="创建时间" width="180" />
        <el-table-column align="center" label="操作">
          <template slot-scope="table">
            <el-button size="mini" type="primary" icon="el-icon-view" @click="viewTable(table.row.name)" />
          </template>
        </el-table-column>
      </el-table>
      <el-pagination v-if="paginate.total > 0" class="pagination_box" background :current-page="paginate.current" :page-sizes="[10, 100, 200, 500]" layout="total, sizes, prev, pager, next, jumper" :total="paginate.total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
    <!-- <el-pagination
      background
      class="pagination-container"
      :current-page="paginate.current"
      hide-on-single-page
      :page-sizes="paginate.sizes"
      :page-size="paginate.limit"
      :layout="paginate.layout"
      :total="paginate.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    /> -->
    <!--------------------------------- 查看表结构 ------------------------------------------------------->
    <el-dialog title="表结构" :visible.sync="visable">
      <el-table v-loading="loadingDia" :data="table" tooltip-effect="dark" style="width: 100%" border fit :max-height="screenHeigh">
        <el-table-column label="字段名称" prop="name" />
        <el-table-column prop="type" label="类型" width="150" />
        <el-table-column prop="notnull" label="NULL" width="150">
          <template slot-scope="field">
            <el-tag type="primary">{{ field.row.notnull == true ? '是' : '否' }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="default" label="默认值" width="150" />
        <el-table-column prop="comment" label="注释" />
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import formOperate from '@/layout/mixin/formOperate'
import cacheList from '@/layout/mixin/cacheList'
export default {
  name: 'SystemDatabase',
  mixins: [formOperate, cacheList],
  data() {
    return {
      otherHeight: 335,
      componentName: 'SystemDatabase',
      url: 'tables',
      queryParam: {
        tablename: '',
        engine: ''
      },
      visable: false,
      table: [],
      loadingDia: false
    }
  },
  methods: {
    viewTable(tablename) {
      this.visable = true
      this.loadingDia = true
      this.$http.get('table/view/' + tablename).then(res => {
        this.table = res.data
        this.loadingDia = false
      }).catch(() => {
        this.loadingDia = false
      })
    }
  }
}
</script>

<style scoped>
</style>
